<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:au="http://java.sun.com/jsf/composite/autocomplete">

    <h:body>

        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form>
                    <p:panel header="Issue Margin">

                        <p:panel header="Add new Issue Margin" >
                            <p:panelGrid columns="2" >
                                <h:outputLabel value="From Department :" />
                                <au:department value="#{issueRateMarginsController.fromDepartment}"/>
                                <h:outputLabel value="To Department :" />
                                <au:department value="#{issueRateMarginsController.issueRateMargins.toDepartment}"/>
                                <h:outputLabel value="At Purchase Rate" ></h:outputLabel>
                                <p:selectBooleanCheckbox value="#{issueRateMarginsController.issueRateMargins.atPurchaseRate}" />                               
                                <h:outputLabel value="Margin" ></h:outputLabel>
                                <p:inputText autocomplete="off" value="#{issueRateMarginsController.issueRateMargins.rateForPharmaceuticals}" />                                
                                <p:commandButton value="Add" ajax="false" action="#{issueRateMarginsController.add()}" 
                                                 onclick="onSubmitButton();" >
                                </p:commandButton>

                            </p:panelGrid>                          
                            <p:commandButton ajax="false" value="Fill" 
                                            action="#{issueRateMarginsController.createMargins()}" 
                                             onclick="onSubmitButton();"/>
                            
                             <p:commandButton ajax="false" value="Add All" 
                                            action="#{issueRateMarginsController.addAllDep()}" 
                                             onclick="onSubmitButton();"/>
                           

                        </p:panel>

                        <p:panel header="Price Matrix" >

                            <p:dataTable 
                                value="#{issueRateMarginsController.items}" 
                                var="a" 
                                paginator="true"
                                paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                rowsPerPageTemplate="5,10,15"
                                >

                                <p:column headerText="From Department" filterBy="#{a.fromDepartment.name}" filterMatchMode="contains" exportable="false">
                                    <au:department value="#{a.fromDepartment}"/>
                                </p:column>
                                <p:column headerText="To Department" filterBy="#{a.toDepartment.name}" filterMatchMode="contains" exportable="false">
                                    <au:department value="#{a.toDepartment}"/>
                                </p:column>
                                
                                  <p:column headerText="At Purchase Rate">
                                   <p:selectBooleanCheckbox value="#{a.atPurchaseRate}" />                               
                                </p:column>

                                <p:column headerText="Margin">
                                    <h:inputText autocomplete="off" value="#{a.rateForPharmaceuticals}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:inputText>
                                </p:column>

                                <p:column>
                                    <p:commandButton ajax="false" value="Update" action="#{issueRateMarginsController.onEdit(a)}" onclick="onSubmitButton();"/> 
                                </p:column>
                                <p:column>
                                    <p:commandButton value="Delete" action="#{issueRateMarginsController.delete(a)}" onclick="onSubmitButton();">                                        
                                    </p:commandButton>
                                </p:column>

                            </p:dataTable>


                        </p:panel>

                    </p:panel>

                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
